mirror of https://github.com/wg-easy/wg-easy
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.2 KiB
43 lines
1.2 KiB
import { createError, getValidatedRouterParams } from 'h3';
|
|
|
|
import Database from '#server/utils/Database';
|
|
import { definePermissionEventHandler } from '#server/utils/handler';
|
|
import { resolveClientEffectivePolicy } from '#shared/utils/clientPolicy';
|
|
import { validateZod } from '#server/utils/types';
|
|
import { ClientGetSchema } from '#db/repositories/client/types';
|
|
|
|
export default definePermissionEventHandler(
|
|
'clients',
|
|
'view',
|
|
async ({ event, checkPermissions }) => {
|
|
const { clientId } = await getValidatedRouterParams(
|
|
event,
|
|
validateZod(ClientGetSchema, event)
|
|
);
|
|
|
|
const client = await Database.clients.get(clientId);
|
|
checkPermissions(client);
|
|
|
|
if (!client) {
|
|
throw createError({
|
|
statusCode: 404,
|
|
statusMessage: 'Client not found',
|
|
});
|
|
}
|
|
|
|
const [wgInterface, userConfig, groups] = await Promise.all([
|
|
Database.interfaces.get(),
|
|
Database.userConfigs.get(),
|
|
Database.clientGroups.getGroupsForClient(clientId),
|
|
]);
|
|
|
|
const policy = resolveClientEffectivePolicy({
|
|
client,
|
|
groups,
|
|
userConfig,
|
|
firewallEnabled: wgInterface.firewallEnabled,
|
|
});
|
|
|
|
return policy.fields;
|
|
}
|
|
);
|
|
|